<?php

Yii::import('zii.widgets.jui.CJuiDatePicker');

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of elRTE
 *
 * @author god
 */
class EJuiTimePicker extends CJuiDatePicker {


	/**
	* Run the widget, including the js files.
	*/
	public function run() {
		$dir= dirname(__FILE__) . DIRECTORY_SEPARATOR;
		$baseUrl= Yii::app()->getAssetManager()->publish($dir);

		list($name,$id)=$this->resolveNameID();

		if(isset($this->htmlOptions['id']))
			$id=$this->htmlOptions['id'];
		else
			$this->htmlOptions['id']=$id;
		if(isset($this->htmlOptions['name']))
			$name=$this->htmlOptions['name'];
		else
			$this->htmlOptions['name']=$name;

		if($this->hasModel())
			echo CHtml::activeTextField($this->model,$this->attribute,$this->htmlOptions);
		else
			echo CHtml::textField($name,$this->value,$this->htmlOptions);


		$options=CJavaScript::encode($this->options);

		$js = "jQuery('#{$id}').timepicker($options);";

		if (isset($this->language)){
			$this->registerScriptFile($this->i18nScriptFile);
			$js = "jQuery('#{$id}').timepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['{$this->language}'], {$options}));";
		}

		$cs = Yii::app()->getClientScript();
		$cs->registerScriptFile($baseUrl . '/js/jquery-ui-timepicker-addon-0.5.js');
		$cs->registerCssFile($baseUrl . '/css/jquery-ui-timepicker-addon-0.5.css');
		$cs->registerScript(__CLASS__, 	$this->defaultOptions?'jQuery.timepicker.setDefaults('.CJavaScript::encode($this->defaultOptions).');':'');
		$cs->registerScript(__CLASS__.'#'.$id, $js);


		//parent::run();
	}
}
?>

